package cn.xinfei.xdecision.thread;

public class TRunable implements Runnable{
    volatile int index=0;

    public TRunable(int index) {
        this.index = index;
    }

    @Override
    public void run() {
        while (true) {
            System.out.println(Thread.currentThread().getName()+"_"+index);
            try {
                index++;
                Thread.sleep(1000);
                if(index>=20){
                    System.out.println(Thread.currentThread().getName()+"-当前线程结束");
                    break;
                }
            } catch (InterruptedException e) {
                e.printStackTrace();
            }
        }
    }

    public static void main(String[] args) {
        TRunable tRunable = new TRunable(0);

        for (int i = 0; i < 10; i++) {
            Thread t=new Thread(tRunable);
            t.setName("t"+i);
            t.start();
        }

    }
}
